function pageReady() {
    layui.use(['form', 'layer', 'layedit', 'laydate', 'upload'], function () {
        var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
            laypage = layui.laypage,
            upload = layui.upload,
            layedit = layui.layedit,
            laydate = layui.laydate,
            $ = layui.jquery;
        //修改提交表单，字典值
        form.on("submit(updateSubmitVal)", function (data) {
            if ("YWLX_T" == $("#typeCode").val() || "YWLX_S" == $("#typeCode").val() || "YWLX_G" == $("#typeCode").val()) {
                var descriptions = [];
                $("input:checkbox:checked").each(function (index, element) {
                    descriptions.push(element.value)
                });
                if (descriptions.length == 0) {
                    $("#description").val("");
                } else {
                    $("#description").val(descriptions.join(","));
                }
            }
            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.1});
            // 实际使用时的提交信息
            $.post("/tu/sys/dictVal/editEntity", {
                id: $("#id").val(),
                valName: $("#valName").val(), //
                valCode: $("#valCode").val(),
                sortIndex: $("#sortIndex").val(),
                description: $("#description").val()
            }, function (res) {

            });
            setTimeout(function () {
                top.layer.close(index);
                top.layer.msg("修改成功！");
                layer.closeAll("iframe");
                layuiFunciton.closeOpen();
                //刷新父页面
                //parent.location.reload();
            }, 500);
            return false;
        })
    });
    console.log($("#typeCode").val())
    //查询
    if ("YWLX_T" == $("#typeCode").val() || "YWLX_S" == $("#typeCode").val() || "YWLX_G" == $("#typeCode").val()) {
        var descriptionsObj = {};
        var descriptions = $("#description").val();
        if (descriptions) {
            var descriptionsList = descriptions.split(",");
            for (var i = 0; i < descriptionsList.length; i++) {
                descriptionsObj[descriptionsList[i]] = (i + 1);
            }
        }
        console.log(descriptionsObj);
        layuiFunciton.ajaxRequest({
            url: layuiFunciton.URL + '/sys/dictVal/getByTypeCode?page=1&limit=999&typeCode=FYLX',
            method: 'get',
            success: function (data) {
                var descriptionHtml = '';
                $(data).each(function (index, obj) {
                    if (descriptionsObj[obj.valCode]) {
                        descriptionHtml += '<input type="checkbox" name="description" value="' + obj.valCode + '" title="' + obj.valName + '" checked>';
                    } else {
                        descriptionHtml += '<input type="checkbox" name="description" value="' + obj.valCode + '" title="' + obj.valName + '">';
                    }
                });
                $("#descriptionHtml").html(descriptionHtml);
            }
        });
    } else if ("FYLX" == $("#typeCode").val()) {
        layuiFunciton.ajaxRequest({
            url: layuiFunciton.URL + '/sys/dictVal/getByTypeCode?page=1&limit=999&typeCode=SKDW',
            method: 'get',
            success: function (data) {
                var descriptionHtml = '';
                $(data).each(function (index, obj) {
                    if (index == 0) {
                        descriptionHtml += '<option value="">请选择</option>';
                    }
                    if (obj.valCode == $("#descriptionValue").val()) {
                        descriptionHtml += '<option value="' + obj.valCode + '" selected>' + obj.valName + '</option>';
                    } else {
                        descriptionHtml += '<option value="' + obj.valCode + '">' + obj.valName + '</option>';
                    }
                });
                $("#description").html(descriptionHtml);
            }
        });
    }
}

